import { UserProfilesAPI } from '../../request/api';

export default {
  namespaced: true,
  state: {
    userInfo: {
      nickName: "游客",
      coin: 0,
      headImg:
        "http://sc.wolfcode.cn/assets/integralMall/img/users/userImg.png",
    },
    cartTotal: 0,
  },
  getters: {},
  mutations: {
    changUserMutation(state, val) {
      (state.userInfo = val.userInfo), (state.cartTotal = val.cartTotal);
    },
    initUserInfo(state) {
      state.cartTotal = 0;
      state.userInfo = {
        nickName: "游客",
        coin: 0,
        headImg:
          "http://sc.wolfcode.cn/assets/integralMall/img/users/userImg.png",
      };
    },
  },
  actions: {
    async asyncUserAction(context) {
      const userRes = await UserProfilesAPI();
      console.log(userRes);
      context.commit("changUserMutation", userRes.data);
    },
  },
};
